package com.xyz.practice.jdbc.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBUtil {

  private final static String db_url = "";
  private final static String username = "";
  private final static String password = "";
  

  static {
    try {
//      Class.forName( "oracle.jdbc.OracleDriver" ); 
      Class.forName( "com.mysql.jdbc.Driver" );
    }
    catch ( ClassNotFoundException e ) {
      e.printStackTrace();
    }
  }

  public static Connection getConnection() {
    return getConnection( db_url, username, password );
  }

  public static Connection getConnection( String dbUrl, String username, String password ) {
    try {
      return DriverManager.getConnection( dbUrl, username, password );
    }
    catch ( SQLException e ) {
      e.printStackTrace();
      return null;
    }
  }

  public static void close( Connection connection ) {
    try {
      connection.close();
    }
    catch ( SQLException e ) {
      e.printStackTrace();
    }
  }

  public static void close( Statement statement ) {
    try {
      statement.close();
    }
    catch ( SQLException e ) {
      e.printStackTrace();
    }
  }

  public static void close( ResultSet resultSet ) {
    try {
      resultSet.close();
    }
    catch ( SQLException e ) {
      e.printStackTrace();
    }
  }

  public static void main( String[] args ) {
    Connection connection = getConnection();
    close( connection );
  }

}
